//1工厂模式

function creatPerson(name, age, words) {
    var obj = new Object(); //生成一个新的空对象
    obj.name = name; //把形式参数name赋值给obj.name
    obj.age = age;
    obj.say = function() {
        console.log(words)
    }
    return obj

}
//f(x) = x +1
//f(1)
// p1 = creatPerson('周杰伦', 30, '哎哟不错！')
// p1.say()
//2.构造函数
function Person(x, y) {
    this.name = x;
    this.age = y;
    this.say = function() { console.log('hello') }

}
// p2 = new Person('周杰伦', 30)
// p2.say()

//3.原型
function Animal() {}

Animal.prototype = {
    legs: 4,
    norse: 1,
    ears: 2,
    type: "哺乳动物"
}
var cat = new Animal()
    // console.log(cat.type)
    // console.log(cat.ears)

function Per() {
    this.country = "中国";
}

function Stu(name, major) {
    this.name = name;
    this.major = major;
}

Stu.prototype = new Per();
console.log(Stu.prototype.constructor); // Per(){ this.country = "中国"; }
// 更正Stu的构造函数
Stu.prototype.constructor = Stu;

var stu = new Stu("小明", "网页设计");